package com.example.myapplication

import android.os.Bundle
import android.view.View
import android.widget.Button
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
    private var btn: Button? = null
    var onClick = View.OnClickListener {
        AlertDialog.Builder(this@MainActivity)
            .setTitle("标题")
            .setMessage("内容")
            .setPositiveButton("确定", null)
            .show()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        btn = findViewById<View>(R.id.button2) as Button
        btn!!.setOnClickListener {
            AlertDialog.Builder(this@MainActivity)
                .setTitle("提示")
                .setMessage("你确定退出")
                .setPositiveButton(
                    "确定"
                ) { dialog, which -> System.exit(0) }
                .setNegativeButton(
                    "取消"
                ) { dialog, which -> dialog.cancel() }
                .create()
                .show()
        }
    }
}